1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 import com.sun.security.auth.module.Krb5LoginModule;
32 import java.io.*;
33 import java.util.HashMap;
34 import java.util.Map;
35 import java.util.regex.Matcher;
36 import java.util.regex.Pattern;
37 import javax.security.auth.Subject;
38
39 public class IPv6 {
40
41 public static void main(String[] args) throws Exception {
42
43 String[][] kdcs = {
44 {"simple.host", null},
45 {"simple.host", ""},
46 {"simple.host", "8080"},
47 {"0.0.0.1", null},
48 {"0.0.0.1", ""},
49 {"0.0.0.1", "8080"},
50 {"1::1", null},
51 {"[1::1]", null},
52 {"[1::1]", ""},
53 {"[1::1]", "8080"},
54 {"[1::1", null},
55 {"[1::1]abc", null},
56 };
57
58 PrintStream out = new PrintStream(new FileOutputStream("ipv6.conf"));
59 out.println("[libdefaults]");
60 out.println("default_realm = V6");
61 out.println("kdc_timeout = 1");
62 out.println("[realms]");
63 out.println("V6 = {");
64 for (String[] hp: kdcs) {
65 if (hp[1] != null) out.println(" kdc = "+hp[0]+":"+hp[1]);
66 else out.println(" kdc = " + hp[0]);
67 }
68 out.println("}");
69 out.close();
70
71 System.setProperty("sun.security.krb5.debug", "true");
72 System.setProperty("java.security.krb5.conf", "ipv6.conf");
73
74 ByteArrayOutputStream bo = new ByteArrayOutputStream();
75 PrintStream po = new PrintStream(bo);
76 PrintStream oldout = System.out;
77 System.setOut(po);
78
79 try {
80 Subject subject = new Subject();
81 Krb5LoginModule krb5 = new Krb5LoginModule();
82 Map<String, String> map = new HashMap<>();
83 Map<String, Object> shared = new HashMap<>();
84
85 map.put("debug", "true");
86 map.put("doNotPrompt", "true");
87 map.put("useTicketCache", "false");
88 map.put("useFirstPass", "true");
89 shared.put("javax.security.auth.login.name", "any");
90 shared.put("javax.security.auth.login.password", "any".toCharArray());
91 krb5.initialize(subject, null, shared, map);
92 krb5.login();
93 } catch (Exception e) {
94
95 }
96
97 po.flush();
98
99 System.setOut(oldout);
100 BufferedReader br = new BufferedReader(new StringReader(
101 new String(bo.toByteArray())));
102 int cc = 0;
103 Pattern r = Pattern.compile(".*KrbKdcReq send: kdc=(.*) UDP:(\\d+),.*");
104 String line;
105 while ((line = br.readLine()) != null) {
106 Matcher m = r.matcher(line.subSequence(0, line.length()));
107 if (m.matches()) {
108 System.out.println("------------------");
109 System.out.println(line);
110 String h = m.group(1), p = m.group(2);
111 String eh = kdcs[cc][0], ep = kdcs[cc][1];
112 if (eh.charAt(0) == '[') {
113 eh = eh.substring(1, eh.length()-1);
114 }
115 System.out.println("Expected: " + eh + " : " + ep);
116 System.out.println("Actual: " + h + " : " + p);
117 if (!eh.equals(h) ||
118 (ep == null || ep.length() == 0) && !p.equals("88") ||
119 (ep != null && ep.length() > 0) && !p.equals(ep)) {
120 throw new Exception("Mismatch");
121 }
122 cc++;
123 }
124 }
125 if (cc != kdcs.length - 2) {
126 throw new Exception("Not traversed");
127 }
128 }
129 }
130
131